package ipgather.util;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class IpUtil {
	private static String IPADDRESS_PATTERN = "(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";
	private static Pattern pattern = Pattern.compile(IPADDRESS_PATTERN);
	
	
	private static String[] executeIps = {"127.0.0.1","192.168.0.1"};//要排除的本地ip地址

	public static Set<String> findIps(String str) {
		Set<String> ips = new HashSet<>();
		Matcher matcher = pattern.matcher(str);
		while (matcher.find()) {
			ips.add(matcher.group());
		}
		for(String ip : executeIps){
			ips.remove(ip);
		}
		return ips;
	}
}
